const path = require('path');
const TerserPlugin = require('terser-webpack-plugin');
const JavaScriptObfuscator = require('webpack-obfuscator');

module.exports = {
  entry: './src/index.js',
  output: {
    path: path.resolve(__dirname, 'dist'),
    filename: 'miniapp.js',
    library: 'MiniApp',
    libraryTarget: 'umd',
    globalObject: 'this'
  },
  module: {
    rules: [
      {
        test: /\.js$/,
        exclude: /node_modules/,
        use: {
          loader: 'babel-loader',
          options: {
            presets: [
              ['@babel/preset-env', {
                targets: "> 0.25%, not dead",
                useBuiltIns: 'usage',
                corejs: 3
              }]
            ]
          }
        }
      }
    ]
  },
  mode: 'production',
  
  optimization: {
    minimize: true,
    minimizer: [new TerserPlugin()],
  },
  
  plugins: [
    new JavaScriptObfuscator({
      rotateUnicodeArray: true,
      stringArray: true,
      stringArrayEncoding: ['base64'],
      seed: 0 // 使用固定的种子以确保构建的一致性
    })
  ],
};